<?php
class Imagen extends Doctrine_Record {
    public function setTableDefinition() {
        $this->setTableName('imagen');
        $this->hasColumn('src', 'string', 255);
        $this->hasColumn('orden', 'integer', 3, array('default'=>0));
        $this->hasColumn('id_producto', 'integer');
        $this->hasColumn('id_slider', 'integer');
    }
    
    public function setUp(){
        $this->hasOne('Producto as producto',array(
            'local'=>'id_producto',
            'foreign'=>'id'
        ));
        $this->hasOne('Slider as slider',array(
            'local'=>'id_slider',
            'foreign'=>'id'
        ));
    }
    
    public static function lastId () {
        $q = Doctrine_Query::create()
            ->select('i.id')
            ->from('Imagen i')
            ->orderBy('i.id desc');
        $result = $q->execute();
        return $result[0]->id;
    }
    
}
?>